const showToast = (title, time) => {
	let duration = 3000
	if (time != null) {
		duration = time
	}
	uni.showToast({
		title: title,
		icon: "none",
		duration: duration
	})
}
const hideToast = () => {
	uni.hideToast();
}
const showLoading = (title, time) => {
	uni.showLoading({
		title: title,
		mask: true
	})
	if (time != null) {
		setTimeout(() => {
			uni.hideLoading();
		}, time * 1000)
	}
}
const hideLoading = () => {
	uni.hideLoading();
}
const showModal = (title, content) => {
	return new Promise((resolve) => {
		uni.showModal({
			title: title,
			content: content,
			success: function(res) {
				
				if(res.confirm == true){
					resolve(true)
				}else{
					resolve(false)
				}
			}
		})
	})
}
const showActionSheet = (array) => {
	return new Promise((resolve) => {
		uni.showActionSheet({
			itemList: array,
			success: function(res) {
				resolve(res.tapIndex + 1)
			},
			fail: function(err) {
				resolve({
					err:err
				})
			}
		});
	})
}

export default {
	showToast,
	hideToast,
	showLoading,
	hideLoading,
	showModal,
	showActionSheet
}
